/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

package ru.teleology.cubefs.api.reflection.metadata;

import ru.teleology.cubefs.api.models.Page;
import ru.teleology.cubefs.api.reflection.NativeType;
import ru.teleology.cubefs.api.reflection.Number;
import ru.teleology.cubefs.api.reflection.Types;

@NativeType(name = Types.NUMBER_FIELD_TYPE)
public class NumberField extends FieldMetadata {
	
	private static final String[] TYPE_NAMES = {
		"Byte", "UByte", "Short", "UShort", "Int", "UInt", "BigInt"
	};
	
	public NumberField(long handle) {
		super(handle);
	}
	
	public void GetValue(Page page, Number number, boolean abi) {
    	GetValue(getHandle(), page.getHandle(), 0, number.getHandle(), abi);
    }
	
	public void GetValue(Page page, Number number) {
    	GetValue(getHandle(), page.getHandle(), 0, number.getHandle(), false);
    }
	
    public void GetValue(Page page, int idx, Number number, boolean abi) {
    	GetValue(getHandle(), page.getHandle(), idx, number.getHandle(), abi);
    }

    public void SetValue(Page page, int idx, Number number, boolean abi) {
    	SetValue(getHandle(), page.getHandle(), idx, number.getHandle(), abi);
    }
    
    public void SetValue(Page page, Number number, boolean abi) {
    	SetValue(getHandle(), page.getHandle(), 0, number.getHandle(), abi);
    }
    
    public void SetValue(Page page, Number number) {
    	SetValue(getHandle(), page.getHandle(), 0, number.getHandle(), false);
    }
    
    public long GetValue(Page page, int idx, boolean abi) {
    	return GetValue(getHandle(), page.getHandle(), idx, abi);
    }
    
    public long GetValue(Page page, boolean abi) {
    	return GetValue(getHandle(), page.getHandle(), 0, abi);
    }
    
    public long GetValue(Page page) {
    	return GetValue(getHandle(), page.getHandle(), 0, false);
    }

    public void SetValue(Page page, int idx, long number, boolean abi) {
    	SetValueLong(getHandle(), page.getHandle(), idx, number, abi);
    }
    
    private static native void GetValue(long me, long page, int idx, long number, boolean abi);
    private static native void SetValue(long me, long page, int idx, long number, boolean abi);
    
    private static native long GetValue(long me, long page, int idx, boolean abi);
    private static native void SetValueLong(long me, long page, int idx, long number, boolean abi);
    
    public String getTypeName() {
		return GetTypeCode() >= 0 ? ( GetTypeCode() < TYPE_NAMES.length ?  TYPE_NAMES[GetTypeCode()] : "" ) : "";
	}
}
